

//
//  WYCMeController.m
//  51还款
//
//  Created by 中企互联 on 2017/10/30.
//  Copyright © 2017年 中企互联. All rights reserved.
//

#import "WYCMeController.h"
#import "WYCRealnameController.h"
#import "WYCAboutMeController.h"
#import "WYCMeWalletController.h"
#import "WYCSetDissController.h"
#import "WYCMessegeController.h"
#import "WYCHelpController.h"
#import "WYCPersonalCenterController.h"
#import "WYCMeTamController.h"
#import "SetGestureLockViewController.h"
#import "WYCMePhotoModel.h"
#import "XMGVerticalButton.h"
#import "WYCLoginController.h"
#import "WYCShimingController.h"
#import "WYCMeWarrantyController.h"

@interface WYCMeController ()


@property(nonatomic,strong)UITableView * tableView;

/** 模型*/
@property(nonatomic,strong)WYCMePhotoModel * MePhotoModel;

/** 头像*/
@property(nonatomic,strong)UIImageView * photoImageView;
@end

@implementation WYCMeController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    //头像View
    [self setupportrait];
    
    
    
//    [self setupRequster];
}

- (void)setupRequster{
    
    NSString * str = [NSString stringWithFormat:@"%@token=%@",userPortraitDetail,[WYCAccountTool unarchivetoken]];
    [HttpTool POST:str params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        WYCLog(@"%@",responseObject);
        
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
            NSDictionary * dict = responseObject[@"result"];
            self.MePhotoModel = [WYCMePhotoModel mj_objectWithKeyValues:dict];
            if (self.MePhotoModel.imgUrl.length == 0){
                self.photoImageView.image = [UIImage imageNamed:@"96"];
                
            }else{
            [self.photoImageView sd_setImageWithURL:[NSURL URLWithString:self.MePhotoModel.imgUrl]];
            }
            }else{
            [SVProgressHUD showImage:[UIImage imageNamed:@""] status:msgStr];
            
        }
        
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
}

#pragma make --------->>>头像View
- (void)setupportrait{
    
    //界面背景颜色
    self.view.backgroundColor = WYCGlobalBg;
    UIView * backView = [[UIView alloc] init];
    backView.backgroundColor = wycMain;
    backView.frame = CGRectMake(0, 0, ScreenWidth, 600 * px);
    [self.view addSubview:backView];
    
    //Nav添加控件
    UIView *navView = [[UIView alloc] init];
    navView.frame = CGRectMake(0, 40 * px, ScreenWidth, 160 * px);
    navView.backgroundColor = trpColor;
    [backView addSubview:navView];
    
    UIButton * remindButton = [[UIButton alloc] init];
    remindButton.frame = CGRectMake(40 * px, 80 * px, 80 * px, 80 * px);
    [remindButton addTarget:self action:@selector(remindButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [remindButton setImage:[UIImage imageNamed:@"ring"] forState:UIControlStateNormal];
    [navView addSubview:remindButton];
    
    UIButton * setButton = [[UIButton alloc] init];
    setButton.frame = CGRectMake(ScreenWidth - 70, 20, 60, 50);
    setButton.titleLabel.font = [UIFont systemFontOfSize:16];
    [setButton addTarget:self action:@selector(SignoutClick) forControlEvents:UIControlEventTouchUpInside];
    [setButton setTitle:@"退出" forState:UIControlStateNormal];
    [navView addSubview:setButton];
    
    
    UIImageView * photoImageView = [[UIImageView alloc] init];
    photoImageView.frame = CGRectMake(ScreenWidth / 2 - 130 * px, CGRectGetMaxY(navView.frame), 260 * px, 260 * px);
    photoImageView.layer.cornerRadius = photoImageView.width / 2;
    photoImageView.layer.masksToBounds = YES;
    [photoImageView setUserInteractionEnabled:YES];
    [photoImageView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showPictureClick)]];
//    photoImageView.backgroundColor = [UIColor whiteColor];
    [backView addSubview:photoImageView];
    self.photoImageView = photoImageView;
    
    
    UILabel * namelabel = [[UILabel alloc] init];
    namelabel.frame = CGRectMake(photoImageView.x, CGRectGetMaxY(photoImageView.frame) + 40 * px, photoImageView.width, 60 * px);
    namelabel.font = [UIFont systemFontOfSize:MiddleFont];
    namelabel.textAlignment = NSTextAlignmentCenter;
    namelabel.textColor = wycwhiteColor;
    namelabel.text = [WYCAccountTool unarchiveuserName];
    [backView addSubview:namelabel];
    
    
    UIView * meView = [[UIView alloc] init];
    meView.frame = CGRectMake(0, CGRectGetMaxY(backView.frame), ScreenWidth, 750 * px);
    meView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:meView];
    
    XMGVerticalButton * nameButton = [[XMGVerticalButton alloc] init];
    nameButton.frame = CGRectMake(0, 30 * px, ScreenWidth / 3, 300 * px);
    [nameButton setImage:[UIImage imageNamed:@"实名认证"] forState:UIControlStateNormal];
    [nameButton addTarget:self action:@selector(nameButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [nameButton setTitle:@"实名认证" forState:UIControlStateNormal];
    [nameButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    nameButton.titleLabel.font = [UIFont systemFontOfSize:SmallFont];
    [meView addSubview:nameButton];
    
    UIView * nameline = [[UIView alloc] init];
    nameline.frame = CGRectMake(0, CGRectGetMaxY(nameButton.frame), ScreenWidth, 0.5);
    nameline.backgroundColor = WYCRGBColor(246, 246, 246);
    [meView addSubview:nameline];
    
    UIView * hightline = [[UIView alloc] init];
    hightline.frame = CGRectMake(CGRectGetMaxX(nameButton.frame), 0, 0.5, 900 * px);
    hightline.backgroundColor = WYCRGBColor(246, 246, 246);
    [meView addSubview:hightline];
    
    
    XMGVerticalButton * walletButton = [[XMGVerticalButton alloc] init];
    walletButton.frame = CGRectMake(ScreenWidth / 3, nameButton.y, ScreenWidth / 3, 300 * px);
    [walletButton setImage:[UIImage imageNamed:@"我的钱包"] forState:UIControlStateNormal];
    [walletButton addTarget:self action:@selector(teamButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [walletButton setTitle:@"我的团队" forState:UIControlStateNormal];
    [walletButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    walletButton.titleLabel.font = [UIFont systemFontOfSize:SmallFont];
    [meView addSubview:walletButton];
    
    
    UIView * walletline = [[UIView alloc] init];
    walletline.frame = CGRectMake(CGRectGetMaxX(walletButton.frame), 0, 0.5, 900 * px);
    walletline.backgroundColor = WYCRGBColor(246, 246, 246);
    [meView addSubview:walletline];
    
    
    XMGVerticalButton * messgeButton = [[XMGVerticalButton alloc] init];
    messgeButton.frame = CGRectMake(ScreenWidth / 3 * 2, nameButton.y, ScreenWidth / 3, 300 * px);
    [messgeButton setImage:[UIImage imageNamed:@"我的保单"] forState:UIControlStateNormal];
    [messgeButton setTitle:@"我的保单" forState:UIControlStateNormal];
    [messgeButton addTarget:self action:@selector(PolicyButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [messgeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    messgeButton.titleLabel.font = [UIFont systemFontOfSize:SmallFont];
    [meView addSubview:messgeButton];
    
    
    XMGVerticalButton * assistantButton = [[XMGVerticalButton alloc] init];
    assistantButton.frame = CGRectMake(nameButton.x, CGRectGetMaxY(nameButton.frame) + 30 * px, ScreenWidth / 3, 300 * px);
    [assistantButton setImage:[UIImage imageNamed:@"支付助手"] forState:UIControlStateNormal];
    [assistantButton addTarget:self action:@selector(assistantButtonClicl) forControlEvents:UIControlEventTouchUpInside];
    [assistantButton setTitle:@"帮助中心" forState:UIControlStateNormal];
    [assistantButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    assistantButton.titleLabel.font = [UIFont systemFontOfSize:SmallFont];
    [meView addSubview:assistantButton];
    
    
    XMGVerticalButton * aboutmeButton = [[XMGVerticalButton alloc] init];
    aboutmeButton.frame = CGRectMake(walletButton.x, assistantButton.y, ScreenWidth / 3, 300 * px);
    [aboutmeButton setImage:[UIImage imageNamed:@"关于我们"] forState:UIControlStateNormal];
    [aboutmeButton setTitle:@"关于我们" forState:UIControlStateNormal];
    [aboutmeButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [aboutmeButton addTarget:self action:@selector(aboutmeButtonClick) forControlEvents:UIControlEventTouchUpInside];
    aboutmeButton.titleLabel.font = [UIFont systemFontOfSize:SmallFont];
    [meView addSubview:aboutmeButton];
    
    
    XMGVerticalButton * setupButton = [[XMGVerticalButton alloc] init];
    setupButton.frame = CGRectMake(messgeButton.x, assistantButton.y, ScreenWidth / 3, 300 * px);
    [setupButton setImage:[UIImage imageNamed:@"设置1"] forState:UIControlStateNormal];
    [setupButton addTarget:self action:@selector(setButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [setupButton setTitle:@"设置" forState:UIControlStateNormal];
    setupButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [setupButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    setupButton.titleLabel.font = [UIFont systemFontOfSize:SmallFont];
    [meView addSubview:setupButton];
    
//    XMGVerticalButton * friendButton = [[XMGVerticalButton alloc] init];
//    friendButton.frame = CGRectMake(nameButton.x, CGRectGetMaxY(nameButton.frame) + 30 * px, ScreenWidth / 3, 300 * px);
//    [friendButton setImage:[UIImage imageNamed:@"邀请好友"] forState:UIControlStateNormal];
//    [friendButton setTitle:@"邀请好友" forState:UIControlStateNormal];
//    [friendButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    friendButton.titleLabel.font = [UIFont systemFontOfSize:SmallFont];
//    [meView addSubview:friendButton];
//
//
//    UIView * friendline = [[UIView alloc] init];
//    friendline.frame = CGRectMake(0, CGRectGetMaxY(friendButton.frame), ScreenWidth, 0.5);
//    friendline.backgroundColor = WYCRGBColor(246, 246, 246);
//    [meView addSubview:friendline];
//
//    XMGVerticalButton * teamButton = [[XMGVerticalButton alloc] init];
//    teamButton.frame = CGRectMake(walletButton.x, friendButton.y, ScreenWidth / 3, 300 * px);
//    [teamButton setImage:[UIImage imageNamed:@"我的团队"] forState:UIControlStateNormal];
//    [teamButton addTarget:self action:@selector(teamButtonClick) forControlEvents:UIControlEventTouchUpInside];
//    [teamButton setTitle:@"我的团队" forState:UIControlStateNormal];
//    [teamButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    friendButton.titleLabel.font = [UIFont systemFontOfSize:SmallFont];
//    [meView addSubview:teamButton];
//
//
//    XMGVerticalButton * PolicyButton = [[XMGVerticalButton alloc] init];
//    PolicyButton.frame = CGRectMake(messgeButton.x, friendButton.y, ScreenWidth / 3, 300 * px);
//    [PolicyButton setImage:[UIImage imageNamed:@"我的保单"] forState:UIControlStateNormal];
//    [PolicyButton addTarget:self action:@selector(PolicyButtonClick) forControlEvents:UIControlEventTouchUpInside];
//    [PolicyButton setTitle:@"我的保单" forState:UIControlStateNormal];
//    [PolicyButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    PolicyButton.titleLabel.font = [UIFont systemFontOfSize:SmallFont];
//    [meView addSubview:PolicyButton];
    
   
    
    UILabel * showlabel = [[UILabel alloc] init];
    showlabel.frame = CGRectMake(0, CGRectGetMaxY(meView.frame)+ 80 * px, ScreenWidth, 60 * px);
    showlabel.font = [UIFont systemFontOfSize:MiddleFont];
    showlabel.textAlignment = NSTextAlignmentCenter;
    showlabel.textColor = [UIColor grayColor];
    showlabel.text = @"客服电话:400-822-7776";
    [self.view addSubview:showlabel];
    
    
    
}
- (void)SignoutClick{
    NSString * str = [NSString stringWithFormat:@"%@token=%@",userlogout,[WYCAccountTool unarchivetoken]];
    [HttpTool POST:str params:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        WYCLog(@"=======%@",responseObject);
        if ([[responseObject objectForKey:@"code"] intValue] == 0) {
            WYCLoginController * login = [[WYCLoginController alloc] init];
            [self presentViewController:login animated:NO completion:nil];
            
//            WYCAccount * Account = [[WYCAccount alloc] initWithDic:dict];

            [WYCAccountTool clearAccount];

            [WYCIsAppLoginTool clearIsAppLogin];
            
            
        }else{
            [SVProgressHUD showImage:[UIImage imageNamed:@""] status:msgStr];
            
        }
    } fail:^(NSURLSessionDataTask *task, NSError *error) {
        [SVProgressHUD showImage:[UIImage imageNamed:@""] status:Failed];
    }];
    
}
// 我的保单
- (void)PolicyButtonClick{
    WYCMeWarrantyController * wallet = [[WYCMeWarrantyController alloc] init];
    [self.navigationController pushViewController:wallet animated:NO];
    
}
#pragma mark -------->>支付助手
- (void)assistantButtonClicl{
    
    WYCHelpController * help = [[WYCHelpController alloc] init];
    [self.navigationController pushViewController:help animated:NO];
}

#pragma mark -------->>实名认证
- (void)nameButtonClick{
    
    WYCShimingController * shiming = [[WYCShimingController alloc] init];
    [self.navigationController pushViewController:shiming animated:NO];
}

#pragma mark ------- >>我的团队
- (void)teamButtonClick{
//    [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"努力开发中..."];
    WYCMeTamController * meTam = [[WYCMeTamController alloc] init];
    [self.navigationController pushViewController:meTam animated:NO];
}
- (void)aboutmeButtonClick{
    WYCAboutMeController * aboutMe = [[WYCAboutMeController alloc] init];
    [self.navigationController pushViewController:aboutMe animated:NO];
    
}

#pragma mark -------->>我的钱包
- (void)walletButtonClick{
//    [SVProgressHUD showImage:[UIImage imageNamed:@""] status:@"努力开发中..."];
    WYCMeWalletController * mewallet = [[WYCMeWalletController alloc] init];
    [self.navigationController pushViewController:mewallet animated:NO];
    
}
#pragma make ------>>消息点击事件
- (void)remindButtonClick{
    WYCLogFunc;
    WYCMessegeController * messege = [[WYCMessegeController alloc] init];
    [self.navigationController pushViewController:messege animated:NO];
    
}

#pragma make ------>>设置点击事件
- (void)setButtonClick
{
    WYCLogFunc;
    WYCSetDissController * setdiss = [[WYCSetDissController alloc] init];
    [self.navigationController pushViewController:setdiss animated:NO];
}
#pragma make ------>>进入控制器隐藏
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    [self setupRequster];
}
#pragma make ------>>离开控制器显示
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

#pragma make ------->>点击头像跳转
- (void)showPictureClick{
    WYCPersonalCenterController * PersonalCenter = [[WYCPersonalCenterController alloc] init];
    [self.navigationController pushViewController:PersonalCenter animated:NO];
         
 }
@end
